package org.akomantoso.core.data;

import java.io.IOException;
import java.util.List;

import org.akomantoso.core.data.attribute.IdReq;
import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.data.attribute.Name;
import org.akomantoso.core.data.attribute.Show;
import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * <pre>
 * <xsd:element name="componentData">
 * 		<xsd:complexType>
 * 			<xsd:sequence minOccurs="0" maxOccurs="unbounded">
 * 				<xsd:element ref="componentData"/>
 * 			</xsd:sequence>
 * 			<xsd:attributeGroup ref="idreq"/>
 * 			<xsd:attributeGroup ref="name"/>
 * 			<xsd:attributeGroup ref="link"/>
 * 			<xsd:attributeGroup ref="show"/>
 *		</xsd:complexType>
 * </xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class ComponentData implements IdReq, Name, Link, Show , Externalizable {

	public static final String ELEMENT = "componentData";
	
	private List<ComponentData> _componentData;
	private String _href;
	private String _id;
	private String _evolvingId;
	private String _name;
	private String _showAs;
	private String _shortForm;

	
	/**
	 * @return the componentData
	 */
	public List<ComponentData> getComponentData() {
		return _componentData;
	}

	/**
	 * @param componentData the componentData to set
	 */
	public void setComponentData(List<ComponentData> componentData) {
		_componentData = componentData;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#getId()
	 */
	public String getId() {
		return _id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#setId(java.lang.String)
	 */
	public void setId(String id) {
		_id = id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#getEvolvingId()
	 */
	public String getEvolvingId() {
		return _evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#setEvolvingId(java.lang.String)
	 */
	public void setEvolvingId(String evolvingId) {
		_evolvingId = evolvingId;
	}
	
	/**
	 * @see org.akomantoso.core.data.attribute.Show#getShowAs()
	 */
	public String getShowAs() {
		return _showAs;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#setShowAs(java.lang.String)
	 */
	public void setShowAs(String showAs) {
		_showAs = showAs;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#getShortForm()
	 */
	public String getShortForm() {
		return _shortForm;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#setShortForm(java.lang.String)
	 */
	public void setShortForm(String shortForm) {
		_shortForm = shortForm;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	public String getHref() {
		return _href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	public void setHref(String href) {
		_href = href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Name#getName()
	 */
	public String getName() {
		return _name;
	}

	/** 
	 * @see org.akomantoso.core.data.attribute.Name#setName(java.lang.String)
	 */
	public void setName(String name) {
		_name = name;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeIdReq(out, this);
		OutputUtil.writeLink(out, this);
		OutputUtil.writeMandatoryAttribute(out, Name.ATTRIBUTE, _name, this);
		OutputUtil.writeShow(out, this);
		if (_componentData != null) {
			for (int i = 0, n = _componentData.size(); i < n; i++) {
				_componentData.get(i).writeExternal(out);
			}
		}
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_id = in.readAttribute(IdReq.ATTRIBUTE_ID);
		_evolvingId = in.readAttribute(IdReq.ATTRIBUTE_EVOLVING_ID);
		_name = in.readAttribute(Name.ATTRIBUTE);
		_href = in.readAttribute(Link.ATTRIBUTE);
		_showAs = in.readAttribute(Show.ATTRIBUTE_SHOW_AS);
		_shortForm = in.readAttribute(Show.ATTRIBUTE_SHORT_FORM);
	}
	
}